package com.ruoyi.accounting.service.impl;

import com.ruoyi.accounting.domain.AccAccount;
import com.ruoyi.accounting.mapper.AccAccountMapper;
import com.ruoyi.accounting.service.AccAccountService;
import com.ruoyi.common.core.enums.DelFlag;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 账户Service业务层处理
 *
 * @author dpf
 * @date 2025-07-17
 */
@Service
@Slf4j
public class AccAccountServiceImpl implements AccAccountService {
    @Autowired
    private AccAccountMapper accAccountMapper;

    /**
     * 查询账户
     *
     * @param id 账户主键
     * @return 账户
     */
    @Override
    public AccAccount selectAccAccountById(Long id) {
        return accAccountMapper.selectAccAccountById(id);
    }

    /**
     * 查询账户列表
     *
     * @param accAccount 账户
     * @return 账户
     */
    @Override
    public List<AccAccount> selectAccAccountList(AccAccount accAccount) {
        return accAccountMapper.selectAccAccountList(accAccount);
    }

    /**
     * 新增账户
     *
     * @param accAccount 账户
     * @return 结果
     */
    @Override
    public int insertAccAccount(AccAccount accAccount) {
        accAccount.setCreateTime(DateUtils.getNowDate());
        accAccount.setCreateBy(SecurityUtils.getUsername());
        accAccount.setDelFlag(DelFlag.normal.getCode());
        return accAccountMapper.insertAccAccount(accAccount);
    }

    /**
     * 修改账户
     *
     * @param accAccount 账户
     * @return 结果
     */
    @Override
    public int updateAccAccount(AccAccount accAccount) {
        accAccount.setUpdateTime(DateUtils.getNowDate());
        return accAccountMapper.updateAccAccount(accAccount);
    }

    /**
     * 批量删除账户
     *
     * @param ids 需要删除的账户主键
     * @return 结果
     */
    @Override
    public int deleteAccAccountByIds(Long[] ids) {
        return accAccountMapper.deleteAccAccountByIds(ids);
    }

    /**
     * 删除账户信息
     *
     * @param id 账户主键
     * @return 结果
     */
    @Override
    public int deleteAccAccountById(Long id) {
        return accAccountMapper.deleteAccAccountById(id);
    }
}
